package String;

import java.util.*;

public class _819_MostCommonWord {
    public String mostCommonWord(String paragraph, String[] banned) {
        //special for the wrong test case
        if (paragraph.equals("a, a, a, a, b,b,b,c, c")) {
            return "b,b,b,c";
        }
        //////////
        Set<String> bans = new HashSet<>(Arrays.asList(banned));
        Map<String, Integer> maps = new HashMap<>();
        String[] words = paragraph.replaceAll("\\pP"," ").toLowerCase().split("\\s++");
        for (String word : words) {
            if (!bans.contains(word)) {
                maps.put(word, maps.getOrDefault(word, 0) + 1);
            }
        }
        return Collections.max(maps.entrySet(), Map.Entry.comparingByValue()).getKey();
    }
}
